package com.dc.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "t_calibration_ship_weld_child")
public class CalibrationShipWeldChildEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "device_no", length = 20)
    private String deviceNo;      // 设备型号

    @Column(name = "start_power")
    public Double startPower;    // 电表起始读数

    @Column(name = "end_power")
    public Double endPower;      // 电表结束读数

    @Transient
    private Long pid;     // 传递 calibration_ship_weld_id 参数

    // persist对级联新增有影响，remove对级联删除有影响，merge对级联修改有影响，refresh对级联查询有影响
    @JsonIgnoreProperties(value = { "inner" })
    @JsonIgnore
    @ManyToOne()
    @JoinColumn(name = "calibration_ship_weld_id", referencedColumnName = "id")
    private CalibrationShipWeldEntity calibrationShipWeldEntity;

    @Override
    public String toString() {
        return "CalibrationShipWeldChildEntity{" +
                "id=" + id +
                ", deviceNo='" + deviceNo + '\'' +
                ", startPower=" + startPower +
                ", endPower=" + endPower +
                ", pid=" + pid +
                ", calibrationShipWeldEntityId=" + calibrationShipWeldEntity.getId() +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CalibrationShipWeldChildEntity that = (CalibrationShipWeldChildEntity) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
